package com.chzc.goods.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chzc.goods.req.GoodsREQ;
import com.chzc.goods.service.IGoodsService;
import com.chzc.po.Goods;
import com.chzc.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *Error: Invalid or corrupt jarfile mq_system-1.0.jar
 * @author CV大魔王
 * @since 2021-05-27
 */
@Api(value = "秒杀商品管理接口(私有)", tags = "秒杀商品管理接口(私有)")
@RestController
@RequestMapping("/pri/goods")
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;

    @ApiOperation("管理员查询商品列表")
    @PostMapping("/search")
    public IPage<Goods> getPageGoods(@RequestBody GoodsREQ req) {
        return goodsService.queryPageList(req);
    }


    @ApiOperation("新增秒杀商品接口")
    @PostMapping
    public Result save(@RequestBody Goods goods) {
        return goodsService.addGoods(goods);
    }


    @ApiOperation("删除秒杀商品")
    @ApiImplicitParam(name="id", value="菜单ID", required=true)
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        return goodsService.deleteById(id);
    }


    @ApiOperation("根据id查询商品")
    @GetMapping("/{id}")
    @ApiImplicitParam(name="id", value="菜单ID", required=true)
    public Goods findById(@PathVariable String id){
        return goodsService.findById(id);
    }

    @ApiOperation("编辑秒杀商品接口")
    @PutMapping
    public Result update(@RequestBody Goods goods) {
        return goodsService.updateGoods(goods);
    }


}
